package com.splic.api.controller.product;

import com.github.pagehelper.PageInfo;
import com.splic.api.service.LoginService;
import com.splic.common.core.DeviceContext;
import com.splic.common.core.controller.BaseController;
import com.splic.common.core.domain.ResponseObj;
import com.splic.common.core.redis.RedisCache;
import com.splic.common.exception.BusinessException;
import com.splic.common.utils.ShiroUtils;
import com.splic.common.utils.security.Md5Utils;
import com.splic.product.domain.*;
import com.splic.product.dto.*;
import com.splic.product.service.*;
import com.splic.product.util.ChinaMobileUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

/**
 * 用户相关信息
 */
@RestController
@RequestMapping("/api/user")
@Slf4j
public class ApiUserController extends BaseController {


    @Autowired
    private UserService userServiceImpl;
    @Autowired
    private UserBrowseRecordService userBrowseRecordServiceImpl;
    @Autowired
    private UserCollectionRecordService userCollectionRecordServiceImpl;
    @Autowired
    private UserSetDataService userSetDataServiceImpl;
    @Autowired
    private UserFeedbackService userFeedbackServiceImpl;
    @Autowired
    private UserSubRecordService userSubRecordServiceImpl;
    @Autowired
    private ProductService productServiceImpl;
    @Autowired
    private EmailSendCodeService emailSendCodeServiceImpl;

    @Autowired
    private RedisCache redisCache;

    @Autowired
    private LoginService loginService;

    /**
     * 获取用户信息
     * @return
     */
    @GetMapping("/getUserInfo")
    public ResponseObj<User> getUserInfo(){
        try {
            Long userId = ShiroUtils.getUserId();
            User user = userServiceImpl.selectUserById(userId);
            return ResponseObj.SUCCESS(user);
        }catch (Exception e){
            log.error("用户信息查询失败:{}",e);
            return ResponseObj.ERROR("用户信息查询失败。");
        }
    }

    /**
     * 修改用户信息
     * @return
     */
    @PostMapping("/updateUserInfo")
    public ResponseObj<Boolean> updateUserInfo(@RequestBody User user){
        try {
            Long userId = ShiroUtils.getUserId();
            user.setId(userId);
            userServiceImpl.updateUserInfo(user);
            return ResponseObj.SUCCESS(true);
        }catch (BusinessException e){
            log.error("用户信息修改失败:{}",e);
            return ResponseObj.ERROR(e.getMessage());
        }catch (Exception e){
            log.error("用户信息修改失败:{}",e);
            return ResponseObj.ERROR("用户信息修改失败。");
        }
    }


    /**
     * 修改用户密码
     * @return
     */
    @PostMapping("/updateUserPwd")
    public ResponseObj<Boolean> updateUserPwd(@RequestBody UpdatePwdDto updatePwdDto){
        try {
            Long userId = ShiroUtils.getUserId();
            if(StringUtils.isEmpty(updatePwdDto.getNewPwd())){
                return ResponseObj.ERROR("请您输入新密码。");
            }
            if(StringUtils.isEmpty(updatePwdDto.getConfirmNewPwd())){
                return ResponseObj.ERROR("请您第二次输入新密码以确认。");
            }
            User userOld = userServiceImpl.selectUserById(userId);
            if (userOld == null){
                throw new BusinessException("用户查询失败。");
            }
            if (updatePwdDto.getVerifyType() == 0) {
                if(StringUtils.isEmpty(updatePwdDto.getOldPwd())){
                    return ResponseObj.ERROR("请您输入原密码。");
                }
                if(!StringUtils.equals(updatePwdDto.getNewPwd(),updatePwdDto.getConfirmNewPwd())){
                    return ResponseObj.ERROR("两次输入之密码不一致，请您检查。");
                }
                if (!Md5Utils.hash(updatePwdDto.getOldPwd()).equals(userOld.getPassword())) {
                    throw new BusinessException("原密码输入错误，请重新输入。");
                }
            }
            String regex = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,1000}$";
            if (!updatePwdDto.getNewPwd().matches(regex)) {
                throw new BusinessException("密码不得少于6位，且需同时包含数字和字母。");
            }
            return ResponseObj.SUCCESS(userServiceImpl.updateUserPwd(userId,updatePwdDto));
        }catch (BusinessException e){
            log.error("用户密码修改失败:{}",e);
            return ResponseObj.ERROR(e.getMessage(), String.valueOf(e.getCode()));
        }catch (Exception e){
            log.error("用户密码修改失败:{}",e);
            return ResponseObj.ERROR("用户密码修改失败。");
        }
    }

    /**
     * 密码检测
     * @param
     * @return
     */
    @Deprecated
    @GetMapping("/checkPassword")
    public ResponseObj<Map<String, Object>> checkPassword(){
        try {
            Map<String, Object> map = new HashMap<>();
            User user = userServiceImpl.selectUserById(ShiroUtils.getUserId());
            if (Md5Utils.hash("ej123456").equals(user.getPassword())) {
                map.put("isEmpty", true);
            } else {
                map.put("isEmpty", false);
            }
            map.put("account", user.getAccount());
            return ResponseObj.SUCCESS(map);
        }catch (BusinessException e){
            log.error("密码检测:{}产品{}版本{}设备{}",e.getMessage(),DeviceContext.getProductPackageKey(), DeviceContext.getVersion(), DeviceContext.getDeviceIdentify());
            return ResponseObj.ERROR(e.getMessage());
        }catch (Exception e){
            log.error("密码检测:{}产品{}版本{}设备{}",e.getMessage(),DeviceContext.getProductPackageKey(), DeviceContext.getVersion(), DeviceContext.getDeviceIdentify());
            return ResponseObj.ERROR("检测三方绑定失败");
        }

    }

    /**
     * 完善账号
     * @return
     */
    @PostMapping("/perfectUser")
    public ResponseObj<LoginResultDto> perfectUser(@RequestBody PerfectAccountDto perfectAccountDto){
        try {
            if(StringUtils.isEmpty(perfectAccountDto.getAccount())){
                return ResponseObj.ERROR("请您输入手机号码。");
            }
            if(StringUtils.isEmpty(perfectAccountDto.getPassword())){
                return ResponseObj.ERROR("请您输入密码。");
            }
            if(StringUtils.isEmpty(perfectAccountDto.getConfirmPassword())){
                return ResponseObj.ERROR("请您第二次输入密码以确认。");
            }
            if(!StringUtils.equals(perfectAccountDto.getPassword(),perfectAccountDto.getConfirmPassword())){
                return ResponseObj.ERROR("两次输入之密码不一致，请您检查。");
            }
            String regex = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,1000}$";
            if (!perfectAccountDto.getPassword().matches(regex)) {
                throw new BusinessException("密码不得少于6位，且需同时包含数字和字母。");
            }
            User userNew = userServiceImpl.getByAccount(perfectAccountDto.getAccount());
            User userOrigin = userServiceImpl.selectUserById(ShiroUtils.getUserId());
            if (userNew != null && !Objects.equals(userNew.getId(), userOrigin.getId())) {
                return ResponseObj.ERROR("该手机号已单独注册账户，无法绑定，请您重新输入。");
            }
            if (StringUtils.isNotEmpty(userOrigin.getAccount()) && !userOrigin.getAccount().equals(perfectAccountDto.getAccount())) {
                return ResponseObj.ERROR("已绑定手机号码无法修改");
            }
            User tempUser = new User();
            tempUser.setId(ShiroUtils.getUserId());
            tempUser.setAccount(perfectAccountDto.getAccount());
            tempUser.setPassword(Md5Utils.hash(perfectAccountDto.getPassword()));
            int result = userServiceImpl.update(tempUser);
            LoginResultDto dto = new LoginResultDto();
            if (result == 1) {
                dto.setIsPerfect(true);
                dto.setToken(loginService.getToken(tempUser.getId(),tempUser.getPassword()));
            } else {
                dto.setIsPerfect(false);
            }
            dto.setUserIdentify(userOrigin.getUserIdentify());
            return ResponseObj.SUCCESS(dto);
        }catch (BusinessException e){
            log.error("完善账号失败:{}",e);
            return ResponseObj.ERROR(e.getMessage());
        }catch (Exception e){
            log.error("完善账号失败:{}",e);
            return ResponseObj.ERROR("完善账号修改失败。");
        }
    }

    /**
     * 修改手机号
     * @return
     */
    @PostMapping("/updateAccount")
    public ResponseObj<Boolean> updateAccount(@RequestBody UpdateAccountDto updateAccountDto){
        try {
            if(StringUtils.isEmpty(updateAccountDto.getNewAccount())){
                return ResponseObj.ERROR("请您输入新手机号码。");
            }
            if (updateAccountDto.getVerifyType() == 0) {
                if (StringUtils.isEmpty(updateAccountDto.getPassword())) {
                    return ResponseObj.ERROR("请输入密码。");
                }
                User userOld = userServiceImpl.selectUserById(ShiroUtils.getUserId());
                if (!Md5Utils.hash(updateAccountDto.getPassword()).equals(userOld.getPassword())) {
                    return ResponseObj.ERROR("密码输入错误，请重新输入。");
                }
            }
            return ResponseObj.SUCCESS(userServiceImpl.updateAccount(updateAccountDto));
        }catch (BusinessException e){
            log.error("手机号修改失败:{}",e);
            return ResponseObj.ERROR(e.getMessage(), String.valueOf(e.getCode()));
        }catch (Exception e){
            log.error("手机号修改失败:{}",e);
            return ResponseObj.ERROR("手机号修改失败。");
        }
    }

    /**
     * 修改用户youxiang
     * @return
     */
    @PostMapping("/updateEmail")
    public ResponseObj<Boolean> updateEmail(@RequestBody UpdateEmailDto updateEmailDto){
        try {
            if(StringUtils.isEmpty(updateEmailDto.getNewEmail())){
                return ResponseObj.ERROR("请您输入新邮箱。");
            }
            if (updateEmailDto.getVerifyType() == 0) {
                User sameUser = userServiceImpl.getByEmail(updateEmailDto.getNewEmail());
                if (sameUser != null) {
                    return ResponseObj.ERROR("该邮箱已被使用，请您绑定其他邮箱。");
                }
                if (StringUtils.isEmpty(updateEmailDto.getPassword())) {
                    return ResponseObj.ERROR("请输入密码。");
                }
                User userOld = userServiceImpl.selectUserById(ShiroUtils.getUserId());
                if (!Md5Utils.hash(updateEmailDto.getPassword()).equals(userOld.getPassword())) {
                    return ResponseObj.ERROR("密码输入错误，请重新输入。");
                }
            }
            return ResponseObj.SUCCESS(userServiceImpl.updateUserEmail(updateEmailDto));
        }catch (BusinessException e){
            log.error("邮箱修改失败:{}",e);
            return ResponseObj.ERROR(e.getMessage());
        }catch (Exception e){
            log.error("邮箱修改失败:{}",e);
            return ResponseObj.ERROR("邮箱修改失败。");
        }
    }

    /**
     * 重置密码账号验证判断
     * @return
     */
    @PostMapping("/resetCheck")
    public ResponseObj<Integer> resetCheck(@RequestBody ResetPwdDto resetPwdDto){
        try {
            if(StringUtils.isEmpty(resetPwdDto.getAccount())){
                return ResponseObj.ERROR("请您输入手机号或邮箱。");
            }
            User userOld = userServiceImpl.selectUserById(ShiroUtils.getUserId());
            if (userOld == null) {
                if (resetPwdDto.getAccount().contains("@")) {
                    User user = userServiceImpl.getByEmail(resetPwdDto.getAccount());
                    if (user == null) {
                        return ResponseObj.ERROR("找不到对应的账号，请您检查输入内容。");
                    }
                    SendCodeDto sendCodeDto = new SendCodeDto();
                    sendCodeDto.setAccount(resetPwdDto.getAccount());
                    sendCodeDto.setType("up_pass");
                    if (emailSendCodeServiceImpl.sendEmailCode(sendCodeDto)) {
//                    邮箱验证码发送成功
                        return ResponseObj.SUCCESS(1);
                    } else {
//                    邮箱验证码发送失败
                        return ResponseObj.SUCCESS(0);
                    }
                } else {
                    User user = userServiceImpl.getByAccount(resetPwdDto.getAccount());
                    if (user == null) {
                        return ResponseObj.ERROR("找不到对应的账号，请您检查输入内容。");
                    }
                    Product product = productServiceImpl.getByPackageKey(DeviceContext.getProductPackageKey());
                    if (ChinaMobileUtils.checkMobile(resetPwdDto.getAccount(), resetPwdDto.getToken(), product.getCmAppId(), product.getCmAppKey(), product.getCmPublicKey())) {
                        redisCache.setCacheObject("reset" + user.getUserIdentify(), 2, 60, TimeUnit.SECONDS);
                        return ResponseObj.SUCCESS(2);
                    } else {
                        if (StringUtils.isEmpty(user.getEmail())) {
                            return ResponseObj.ERROR("您的账号还没有绑定邮箱，请您在安装账号号码的手机上进行密码重置操作。");
                        }
                        SendCodeDto sendCodeDto = new SendCodeDto();
                        sendCodeDto.setAccount(user.getEmail());
                        sendCodeDto.setType("up_pass");
                        if (emailSendCodeServiceImpl.sendEmailCode(sendCodeDto)) {
//                    邮箱验证码发送成功
                            return ResponseObj.SUCCESS(1);
                        } else {
//                    邮箱验证码发送失败
                            return ResponseObj.SUCCESS(0);
                        }
                    }
                }
            } else {
                if (Md5Utils.hash("ej123456").equals(userOld.getPassword())) {
                    redisCache.setCacheObject("reset" + userOld.getUserIdentify(), 4, 60, TimeUnit.SECONDS);
                    return ResponseObj.SUCCESS(4);
                } else {
                    Product product = productServiceImpl.getByPackageKey(DeviceContext.getProductPackageKey());
                    if (ChinaMobileUtils.checkMobile(resetPwdDto.getAccount(), resetPwdDto.getToken(), product.getCmAppId(), product.getCmAppKey(), product.getCmPublicKey())) {
                        redisCache.setCacheObject("reset" + userOld.getUserIdentify(), 2, 60, TimeUnit.SECONDS);
                        return ResponseObj.SUCCESS(2);
                    } else {
                        if (StringUtils.isEmpty(userOld.getEmail())) {
                            return ResponseObj.ERROR("您的账号还没有绑定邮箱，请您在安装账号号码的手机上进行密码重置操作。");
                        }
                        SendCodeDto sendCodeDto = new SendCodeDto();
                        sendCodeDto.setAccount(userOld.getEmail());
                        sendCodeDto.setType("up_pass");
                        if (emailSendCodeServiceImpl.sendEmailCode(sendCodeDto)) {
//                    邮箱验证码发送成功
                            return ResponseObj.SUCCESS(1);
                        } else {
//                    邮箱验证码发送失败
                            return ResponseObj.SUCCESS(0);
                        }
                    }
                }
            }
        }catch (BusinessException e){
            log.error("账号验证判断失败:{}",e);
            return ResponseObj.ERROR(e.getMessage());
        }catch (Exception e){
            log.error("账号验证判断失败:{}",e);
            return ResponseObj.ERROR("账号验证判断失败");
        }
    }

    /**
     * 重置用户密码
     * @return
     */
    @PostMapping("/resetUserPwd")
    public ResponseObj<Boolean> resetUserPwd(@RequestBody ResetPwdDto resetPwdDto){
        try {
            if(StringUtils.isEmpty(resetPwdDto.getAccount())){
                return ResponseObj.ERROR("账号不能为空。");
            }
            if (resetPwdDto.getVerifyType() == 0) {
                if(StringUtils.isEmpty(resetPwdDto.getCode())){
                    return ResponseObj.ERROR("请您输入验证码。");
                }
            } else {
                User user = userServiceImpl.getUserByVague(resetPwdDto.getAccount());
                if (user == null) {
                    return ResponseObj.ERROR("找不到对应的账号，请您检查输入内容。");
                }
                if (!redisCache.hasKey("reset" + user.getUserIdentify())) {
                    return ResponseObj.ERROR("验证过期。");
                }
            }
            if(StringUtils.isEmpty(resetPwdDto.getNewPwd())){
                return ResponseObj.ERROR("请您输入新密码。");
            }
            if(StringUtils.isEmpty(resetPwdDto.getConfirmNewPwd())){
                return ResponseObj.ERROR("请您第二次输入新密码以确认。");
            }
            if(!StringUtils.equals(resetPwdDto.getNewPwd(),resetPwdDto.getConfirmNewPwd())){
                return ResponseObj.ERROR("两次输入之密码不一致，请您检查。");
            }
            String regex = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,1000}$";
            if (!resetPwdDto.getNewPwd().matches(regex)) {
                throw new BusinessException("密码不得少于6位，且需同时包含数字和字母。");
            }
            userServiceImpl.resetUserPwd(resetPwdDto);
            return ResponseObj.SUCCESS(true);
        }catch (BusinessException e){
            log.error("用户密码重置失败:{}",e);
            return ResponseObj.ERROR(e.getMessage());
        }catch (Exception e){
            log.error("用户密码重置失败:{}",e);
            return ResponseObj.ERROR("用户密码重置失败");
        }
    }




    /**
     * 获取用户订阅信息
     * @return
     */
    @GetMapping("/getUserSubList")
    public ResponseObj<List<UserSubRecordResultDto>> getUserSubList(String packageKey){
        try{
            if(StringUtils.isEmpty(packageKey)){
                return ResponseObj.ERROR("应用秘钥不能为空。");
            }
            List<UserSubRecordResultDto> list = userSubRecordServiceImpl.getUserSubRecordList(ShiroUtils.getUserId(),packageKey);
            return ResponseObj.SUCCESS(list);
        }catch (Exception e){
            log.error("用户订阅数据查询失败:{}",e);
            return ResponseObj.ERROR("用户订阅数据查询失败。");
        }
    }



    /**
     *  保存浏览记录
     * @return
     */
    @PostMapping("/saveBrowseRecord")
    public ResponseObj saveBrowseRecord(@RequestBody UserBrowseRecord userBrowseRecord){
        try {
            if(StringUtils.isEmpty(userBrowseRecord.getUrl())){
                return ResponseObj.ERROR("url参数为空");
            }
            userBrowseRecord.setUserId(ShiroUtils.getUserId());
            int count = userBrowseRecordServiceImpl.insert(userBrowseRecord);
            if(count <= 0){
                throw new BusinessException("用户浏览记录保存失败");
            }
            return ResponseObj.SUCCESS();
        }catch (Exception e){
            log.error("用户浏览记录保存失败:{}",e);
            return ResponseObj.ERROR("用户浏览记录保存失败");
        }
    }

    /**
     * 获取浏览记录列表
     * @return
     */
    @GetMapping("/getBrowseRecordList")
    public ResponseObj<PageInfo<UserBrowseRecord>> getBrowseRecordList(int pageNum, int pageSize){
        try{
            startPage();
            UserBrowseRecord userBrowseRecord = new UserBrowseRecord();
            userBrowseRecord.setUserId(ShiroUtils.getUserId());
            List<UserBrowseRecord> list = userBrowseRecordServiceImpl.selectUserBrowseRecordList(userBrowseRecord);
            return ResponseObj.SUCCESS(new PageInfo(list));
        }catch (Exception e){
            log.error("获取历史记录列表失败:{}",e);
            return ResponseObj.ERROR("获取历史记录列表失败");
        }
    }

    /**
     *  保存收藏夹
     * @return
     */
    @PostMapping("/saveCollectionRecord")
    public ResponseObj saveCollectionRecord(@RequestBody UserCollectionRecord userCollectionRecord){
        try {
            if(StringUtils.isEmpty(userCollectionRecord.getUrl())){
                return ResponseObj.ERROR("url参数为空");
            }
            userCollectionRecord.setUserId(ShiroUtils.getUserId());
            int count = userCollectionRecordServiceImpl.insert(userCollectionRecord);
            if(count <= 0){
                throw new BusinessException("用户收藏记录保存失败");
            }
            return ResponseObj.SUCCESS();
        }catch (Exception e){
            log.error("用户收藏记录保存失败:{}",e);
            return ResponseObj.ERROR("用户收藏记录保存失败");
        }
    }

    /**
     * 查询收藏记录列表
     * @return
     */
    @GetMapping("/getCollectionRecordList")
    public ResponseObj<PageInfo<UserCollectionRecord>> getCollectionRecordList(int pageNum, int pageSize){
        try{
            startPage();
            UserCollectionRecord userCollectionRecord = new UserCollectionRecord();
            userCollectionRecord.setUserId(ShiroUtils.getUserId());
            List<UserCollectionRecord> list = userCollectionRecordServiceImpl.selectUserCollectionRecordList(userCollectionRecord);
            return ResponseObj.SUCCESS(new PageInfo(list));
        }catch (Exception e){
            log.error("获取查询收藏记录列表失败:{}",e);
            return ResponseObj.ERROR("获取查询收藏记录列表失败");
        }
    }


    /**
     *  保存用户反馈
     * @return
     */
    @PostMapping("/saveFeedback")
    public ResponseObj saveFeedback(@RequestBody UserFeedback userFeedback){
        try {
            if(StringUtils.isEmpty(userFeedback.getContent())){
                return ResponseObj.ERROR("请您输入吐槽内容。");
            }
            if(StringUtils.isEmpty(userFeedback.getEmail()) && StringUtils.isEmpty(userFeedback.getMobile())
                && StringUtils.isEmpty(userFeedback.getQq()) && StringUtils.isEmpty(userFeedback.getWechat())){
                return ResponseObj.ERROR("请您至少输入手机号和邮箱。");
            }
            if (StringUtils.isEmpty(DeviceContext.getProductPackageKey())){
                throw new BusinessException("应用秘钥为空。");
            }
            userFeedback.setUserId(ShiroUtils.getUserId());
            userFeedbackServiceImpl.saveFeedback(userFeedback);
            return ResponseObj.SUCCESS();
        }catch (Exception e){
            log.error("用户反馈记录保存失败:{}",e);
            return ResponseObj.ERROR("用户反馈记录保存失败");
        }
    }

    /**
     * 查询用户反馈记录列表
     * @return
     */
    @GetMapping("/getFeedbackList")
    public ResponseObj<PageInfo<UserFeedback>> getFeedbackList(int pageNum, int pageSize){
        try{
            startPage();
            UserFeedback userFeedback = new UserFeedback();
            userFeedback.setUserId(ShiroUtils.getUserId());
            List<UserFeedback> list = userFeedbackServiceImpl.selectUserFeedbackList(userFeedback);
            return ResponseObj.SUCCESS(new PageInfo(list));
        }catch (Exception e){
            log.error("获取用户反馈记录列表失败:{}",e);
            return ResponseObj.ERROR("获取用户反馈记录列表失败");
        }
    }


    /**
     *  保存用户设置数据
     * @return
     */
    @PostMapping("/saveUserSetData")
    public ResponseObj saveUserSetData(@RequestBody UserSetData userSetData){
        try {
            if(StringUtils.isEmpty(userSetData.getSetData())){
                return ResponseObj.ERROR("用户设置数据不能为空");
            }
            userSetData.setUserId(ShiroUtils.getUserId());
            int count = userSetDataServiceImpl.insert(userSetData);
            if(count <= 0){
                throw new BusinessException("用户设置数据保存失败");
            }
            return ResponseObj.SUCCESS();
        }catch (Exception e){
            log.error("用户设置数据保存失败:{}",e);
            return ResponseObj.ERROR("用户设置数据保存失败");
        }
    }

    /**
     *  获取用户设置数据列表
     * @return
     */
    @GetMapping("/getUserSetDataList")
    public ResponseObj<PageInfo<UserSetData>> getUserSetDataList(int pageNum, int pageSize){
        try{
            startPage();
            UserSetData userSetData = new UserSetData();
            userSetData.setUserId(ShiroUtils.getUserId());
            List<UserSetData> list = userSetDataServiceImpl.selectUserSetDataList(userSetData);
            return ResponseObj.SUCCESS(new PageInfo(list));
        }catch (Exception e){
            log.error("获取用户设置数据列表失败:{}",e);
            return ResponseObj.ERROR("获取用户设置数据列表失败");
        }
    }

    /**
     * 注销账户
     * @param
     * @return
     */
    @GetMapping("/logOutAccount")
    public ResponseObj logOutAccount(String password,String reason){
        try {
            if (StringUtils.isEmpty(password)){
                return ResponseObj.ERROR("密码不能为空");
            }
            Long userId = ShiroUtils.getUserId();
            userServiceImpl.logOutAccount(userId,password,reason);
            return ResponseObj.SUCCESS();
        }catch (BusinessException e){
            log.error("注销账号失败:{}",e.getMessage());
            return ResponseObj.ERROR(e.getMessage());
        }catch (Exception e){
            log.error("注销账号失败:{}",e.getMessage());
            return ResponseObj.ERROR("注销账号失败。");
        }
    }
}
